using System;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;

namespace Granite.Wcf.Debugging
{
	/// <summary>
	/// Use this for examining how the interface works.
	/// </summary>
	public class DebugContractBehaviorAttribute : DebugAttribute, IContractBehavior
	{
		/// <summary>
		/// Configures any binding elements to support the contract behavior.
		/// </summary>
		/// <param name="contractDescription">
		/// The contract description to modify.
		/// </param>
		/// <param name="endpoint">
		/// The endpoint to modify.
		/// </param>
		/// <param name="bindingParameters">
		/// The objects that binding elements require to support the behavior.
		/// </param>
		public void AddBindingParameters(ContractDescription contractDescription, ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
		{
			WriteLine(string.Format("IEndpointBehavior.Validate: endpoint=\"{0}\"", endpoint.Name));
		}

		/// <summary>
		/// Implements a modification or extension of the client across a contract.
		/// </summary>
		/// <param name="contractDescription">
		/// The contract description for which the extension is intended.
		/// </param>
		/// <param name="endpoint">
		/// The endpoint.
		/// </param>
		/// <param name="clientRuntime">
		/// The client runtime.
		/// </param>
		public void ApplyClientBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, ClientRuntime clientRuntime)
		{
			WriteLine(string.Format("IEndpointBehavior.ApplyClientBehavior: contractType=\"{1}\" endpoint=\"{0}\"", endpoint.Name, contractDescription.ContractType.Name));
		}

		/// <summary>
		/// Implements a modification or extension of the client across a contract.
		/// </summary>
		/// <param name="contractDescription">
		/// The contract description to be modified.
		/// </param>
		/// <param name="endpoint">
		/// The endpoint that exposes the contract.
		/// </param>
		/// <param name="dispatchRuntime">
		/// The dispatch runtime that controls service execution.
		/// </param>
		public void ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime)
		{
			WriteLine(string.Format("IEndpointBehavior.ApplyDispatchBehavior: contractType=\"{1}\" endpoint=\"{0}\"", endpoint.Name, contractDescription.ContractType.Name));
		}

		/// <summary>
		/// Implement to confirm that the contract and endpoint can support the contract behavior.
		/// </summary>
		/// <param name="contractDescription">
		/// The contract to validate.
		/// </param>
		/// <param name="endpoint">
		/// The endpoint to validate.
		/// </param>
		public void Validate(ContractDescription contractDescription, ServiceEndpoint endpoint)
		{
			WriteLine(string.Format("IEndpointBehavior.Validate: contractType=\"{1}\" endpoint=\"{0}\"", endpoint.Name, contractDescription.ContractType.Name));
		}

	}
}
